<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%--
参数：
pagerName：pagerHolder在requestScope里面的名字，默认为"pagerHolder"。
--%>
<%
	String pageHolderName = (String)request.getAttribute("pagerName");
	if (pageHolderName == null) {
		pageHolderName = "pageHolder";
	}
	pageContext.setAttribute("pageHolder",
			request.getAttribute(pageHolderName));
%>
<div>
	<c:if test="${pageHolder.pageCount > 1}">
		<c:set var="defaultInterval" value="5"></c:set>
		<c:set var="defaultBeforeDestorySize" value="5"></c:set>
		<c:set var="defaultShowBeforeSize" value="5"></c:set>
		<c:set var="defaultShowAfterSize" value="2"></c:set>
		<div class="pager">
			总数：${pageHolder.rowCount}条共${pageHolder.pageCount}页
			<c:if test="${!pageHolder.firstPage}">
				<c:url var="nextPage" value="">
					<c:param name="${pageHolder.pageIndexKey}" value="${pageHolder.pageIndex-1}" />
					<c:param name="${pageHolder.rowCountKey}" value="${pageHolder.rowCount}" />
				</c:url>
				<c:url var="indexPage" value="">
					<c:param name="${pageHolder.pageIndexKey}" value="1" />
					<c:param name="${pageHolder.rowCountKey}" value="${pageHolder.rowCount}" />
				</c:url>
				<a href="${indexPage }${pageHolder.params}">首页</a>
				<a href="${nextPage }${pageHolder.params}">上一页</a>
			</c:if>
			<c:choose>
				<c:when test="${pageHolder.pageCount > defaultInterval}">
					<c:set var="pageStart" value="1"></c:set>
					<c:if test="${pageHolder.pageIndex > defaultBeforeDestorySize }">
						<c:set var="pageStart"
							value="${pageHolder.pageIndex - defaultShowBeforeSize}"></c:set>
					</c:if>
					<c:forEach begin="${pageStart }" end="${pageHolder.pageCount }"
						var="pageNum">
						<c:url var="nextPage" value="">
							<c:param name="${pageHolder.pageIndexKey}" value="${pageNum}" />
							<c:param name="${pageHolder.rowCountKey}" value="${pageHolder.rowCount}" />
						</c:url>
						<c:if test="${pageHolder.pageIndex eq pageNum}">
							<span class="current">${pageNum }</span>
						</c:if>
						<c:if
							test="${pageNum <= pageStart+defaultShowBeforeSize || pageNum > pageHolder.pageCount-defaultShowAfterSize}">
							<c:if test="${pageHolder.pageIndex != pageNum}">
								<a href="${nextPage }${pageHolder.params}">${pageNum }</a>
							</c:if>
						</c:if>
						<c:if test="${pageNum == pageHolder.pageCount-defaultShowAfterSize-1}">
									...
						</c:if>
					</c:forEach>
				</c:when>
				<c:otherwise>
					<c:forEach begin="1" end="${pageHolder.pageCount }" var="pageNum">
						<c:url var="nextPage" value="">
							<c:param name="${pageHolder.pageIndexKey}" value="${pageNum}" />
							<c:param name="${pageHolder.rowCountKey}" value="${pageHolder.rowCount}" />
						</c:url>
						<c:if test="${pageHolder.pageIndex eq pageNum}">
							<span class="current">${pageNum }</span>
						</c:if>
						<c:if test="${pageHolder.pageIndex != pageNum}">
							<a href="${nextPage }${pageHolder.params}">${pageNum }</a>
						</c:if>
					</c:forEach>
				</c:otherwise>
			</c:choose>
			<c:if test="${!pageHolder.lastPage}">
				<c:url var="nextPage" value="">
					<c:param name="${pageHolder.pageIndexKey}" value="${pageHolder.pageIndex+1}" />
					<c:param name="${pageHolder.rowCountKey}" value="${pageHolder.rowCount}" />
				</c:url>
				<c:url var="endPage" value="">
					<c:param name="${pageHolder.pageIndexKey}" value="${pageHolder.pageCount}" />
					<c:param name="${pageHolder.rowCountKey}" value="${pageHolder.rowCount}" />
				</c:url>
				<a href="${nextPage }${pageHolder.params}">下一页</a>
				<a href="${endPage }${pageHolder.params}">末页</a>
			</c:if>
			<a href="javascript:location.reload()">刷新</a>
		</div>
	</c:if>
</div>
